﻿using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;

namespace HardcoreGame.Content.Items.Consumables.Others
{
    public class ManaFruit : ModItem
    {

        public override void SetStaticDefaults()
        {
            Item.ResearchUnlockCount = 10;
        }
        public override void SetDefaults()
        {
            Item.maxStack = Item.CommonMaxStack;
            Item.consumable = true;
            Item.width = 18;
            Item.height = 18;
            Item.useStyle = 4;
            Item.useTime = 30;
            Item.UseSound = SoundID.Item4;
            Item.useAnimation = 30;
            Item.rare = 7;
            Item.value = Item.sellPrice(0, 2);
        }
        public override bool CanUseItem(Player player) => player.statMana >= 200 && player.GetModPlayer<ManaFruitPlayer>().goldenStars switch
        {
            < ManaFruitPlayer.goldenStarsMax => true,
            _ => false,
        };
        public override bool? UseItem(Player player)
        {
            player.ManaEffect(5);
            player.statManaMax2 += 5;
            player.GetModPlayer<ManaFruitPlayer>().goldenStars += 1;
            return true;
        }
    }
    public class ManaFruitPlayer : ModPlayer
    {
        public int goldenStars;
        public const int goldenStarsMax = 10;
        public override void ResetEffects()
        {
            Player.statManaMax2 += 5 * goldenStars;
        }
        public override void SaveData(TagCompound tag)
        {
            tag["GStars"] = goldenStars;
        }
        public override void LoadData(TagCompound tag)
        {
            goldenStars = tag.GetInt("GStars");
        }
    }
}
